package com.xw.qxypt;

import com.xw.qxypt.datasource.annotation.DataSource;
import com.xw.qxypt.modules.entity.LhpAlertEntity;
import com.xw.qxypt.modules.service.LhpAlertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
public class DataSourceTestServices {
    @Autowired
    private LhpAlertService lhpAlertService;

    @Transactional
    public void insertAlert(){
        LhpAlertEntity alertEntity=new LhpAlertEntity();
        alertEntity.setAlertInfo("测试主数据源");
        alertEntity.setAlertTime(new Date());
        lhpAlertService.save(alertEntity);
    }

    @Transactional
    @DataSource("slave1")
    public void insertAlertBySlave(){
        LhpAlertEntity alertEntity=new LhpAlertEntity();
        alertEntity.setAlertInfo("测试从数据源");
        alertEntity.setAlertTime(new Date());
        lhpAlertService.save(alertEntity);
    }
}
